
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>前端Js常用的60余种工具方法 · 记录技术文档内容</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="zhengyuliang">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="前端异常的捕获与处理.html" />
    
    
    <link rel="prev" href="this、apply、call、bind.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">CSS</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../CSS/18种CSS命名和书写规范.html">
            
                <a href="../CSS/18种CSS命名和书写规范.html">
            
                    
                    18种CSS命名和书写规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../CSS/灵活运用CSS开发技巧.html">
            
                <a href="../CSS/灵活运用CSS开发技巧.html">
            
                    
                    灵活运用CSS开发技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../CSS/自适应 flex grid.html">
            
                <a href="../CSS/自适应 flex grid.html">
            
                    
                    自适应 Flex Grid
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">HTML</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../HTML/浏览器里的本地数据库：IndexedDB.html">
            
                <a href="../HTML/浏览器里的本地数据库：IndexedDB.html">
            
                    
                    浏览器里的本地数据库：IndexedDB
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Vue</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../Vue/7个有用的Vue开发技巧.html">
            
                <a href="../Vue/7个有用的Vue开发技巧.html">
            
                    
                    7个有用的Vue开发技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../Vue/Vue this.$router.push、replace、go的区别.html">
            
                <a href="../Vue/Vue this.$router.push、replace、go的区别.html">
            
                    
                    Vue This.$Router.Push、Replace、Go的区别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../Vue/Vue 的父组件和子组件生命周期钩子函数执行顺序？.html">
            
                <a href="../Vue/Vue 的父组件和子组件生命周期钩子函数执行顺序？.html">
            
                    
                    Vue 的父组件和子组件生命周期钩子函数执行顺序？
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../Vue/Vue.set和this.$set应用的场景.html">
            
                <a href="../Vue/Vue.set和this.$set应用的场景.html">
            
                    
                    Vue.Set和This.$Set应用的场景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../Vue/vue高级技巧.html">
            
                <a href="../Vue/vue高级技巧.html">
            
                    
                    Vue高级技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../Vue/从 0 开始手把手带你搭建一套规范的 Vue3.x 项目工程环境.html">
            
                <a href="../Vue/从 0 开始手把手带你搭建一套规范的 Vue3.x 项目工程环境.html">
            
                    
                    从 0 开始手把手带你搭建一套规范的 Vue3.X 项目工程环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../Vue/浅析 vue-router 源码和动态路由权限分配.html">
            
                <a href="../Vue/浅析 vue-router 源码和动态路由权限分配.html">
            
                    
                    浅析 Vue Router 源码和动态路由权限分配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../Vue/父组件监听到子组件的生命周期.html">
            
                <a href="../Vue/父组件监听到子组件的生命周期.html">
            
                    
                    父组件监听到子组件的生命周期
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="../Vue/理解Vue.mixin，利用Vue.mixin正确的偷懒.html">
            
                <a href="../Vue/理解Vue.mixin，利用Vue.mixin正确的偷懒.html">
            
                    
                    理解Vue.Mixin，利用Vue.Mixin正确的偷懒
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">JavaScript</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="5个技巧让你更好的编写 JavaScript(ES6">
            
                <span>
            
                    
                    5个技巧让你更好的编写 JavaScript(ES6) 中条件语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="5种常见函数的写法和调用方式.html">
            
                <a href="5种常见函数的写法和调用方式.html">
            
                    
                    5种常见函数的写法和调用方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="7道javascript题，让你理解基本的javascript.html">
            
                <a href="7道javascript题，让你理解基本的javascript.html">
            
                    
                    7道Javascript题，让你理解基本的Javascript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Array.from(">
            
                <span>
            
                    
                    Array.From() 五个超好用的用途
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="ES6汇总资料.html">
            
                <a href="ES6汇总资料.html">
            
                    
                    ES6汇总资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="JS开发必须知道的41个技巧.html">
            
                <a href="JS开发必须知道的41个技巧.html">
            
                    
                    JS开发必须知道的41个技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="JavaScript之防抖Debounce和节流Throttle.html">
            
                <a href="JavaScript之防抖Debounce和节流Throttle.html">
            
                    
                    JavaScript之防抖Debounce和节流Throttle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="JavaScript数组求并集，交集和差集.html">
            
                <a href="JavaScript数组求并集，交集和差集.html">
            
                    
                    JavaScript数组求并集，交集和差集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="JavaScript的优雅写法.html">
            
                <a href="JavaScript的优雅写法.html">
            
                    
                    JavaScript的优雅写法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="axios知识点.html">
            
                <a href="axios知识点.html">
            
                    
                    Axios知识点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="javascript核心知识.html">
            
                <a href="javascript核心知识.html">
            
                    
                    Javascript核心知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="this、apply、call、bind.html">
            
                <a href="this、apply、call、bind.html">
            
                    
                    This、Apply、Call、Bind
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.13" data-path="前端js常用的60余种工具方法.html">
            
                <a href="前端js常用的60余种工具方法.html">
            
                    
                    前端Js常用的60余种工具方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="前端异常的捕获与处理.html">
            
                <a href="前端异常的捕获与处理.html">
            
                    
                    前端异常的捕获与处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.15" data-path="在 JavaScript 中交换值的 10 种方法.html">
            
                <a href="在 JavaScript 中交换值的 10 种方法.html">
            
                    
                    在 JavaScript 中交换值的 10 种方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.16" data-path="常用的前端JavaScript方法封装.html">
            
                <a href="常用的前端JavaScript方法封装.html">
            
                    
                    常用的前端JavaScript方法封装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.17" data-path="异步神器Async-await介绍与填坑.html">
            
                <a href="异步神器Async-await介绍与填坑.html">
            
                    
                    异步神器Async Await介绍与填坑
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.18" data-path="灵活运用JS开发技巧.html">
            
                <a href="灵活运用JS开发技巧.html">
            
                    
                    灵活运用JS开发技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.19" data-path="编写高质量可维护的代码：一目了然的注释.html">
            
                <a href="编写高质量可维护的代码：一目了然的注释.html">
            
                    
                    编写高质量可维护的代码：一目了然的注释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.20" data-path="编写高质量可维护的代码：优化逻辑判断.html">
            
                <a href="编写高质量可维护的代码：优化逻辑判断.html">
            
                    
                    编写高质量可维护的代码：优化逻辑判断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.21" data-path="编写高质量可维护的代码：优雅命名.html">
            
                <a href="编写高质量可维护的代码：优雅命名.html">
            
                    
                    编写高质量可维护的代码：优雅命名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.22" data-path="编写高质量可维护的代码：数据建模.html">
            
                <a href="编写高质量可维护的代码：数据建模.html">
            
                    
                    编写高质量可维护的代码：数据建模
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Life Exp</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../life_exp/告别平庸的15个小方法.html">
            
                <a href="../life_exp/告别平庸的15个小方法.html">
            
                    
                    告别平庸的15个小方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../life_exp/日志记录.html">
            
                <a href="../life_exp/日志记录.html">
            
                    
                    日志记录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../life_exp/程序员的发展方向.html">
            
                <a href="../life_exp/程序员的发展方向.html">
            
                    
                    程序员的发展方向
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../message/">
            
                <a href="../message/">
            
                    
                    Message
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Technology</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../technology/WebSocket.html">
            
                <a href="../technology/WebSocket.html">
            
                    
                    WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../technology/npm常用命令大全.html">
            
                <a href="../technology/npm常用命令大全.html">
            
                    
                    Npm常用命令大全
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="../technology/智能照明项目说明.html">
            
                <a href="../technology/智能照明项目说明.html">
            
                    
                    智能照明项目说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="../technology/规范化git的提交信息.html">
            
                <a href="../technology/规范化git的提交信息.html">
            
                    
                    规范化Git的提交信息
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Tutorial</li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../tutorial/Esmap地图详解.html">
            
                <a href="../tutorial/Esmap地图详解.html">
            
                    
                    Esmap地图详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="../tutorial/npm镜像切换.html">
            
                <a href="../tutorial/npm镜像切换.html">
            
                    
                    Npm镜像切换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="../tutorial/发布npm的教程.html">
            
                <a href="../tutorial/发布npm的教程.html">
            
                    
                    发布Npm的教程
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >前端Js常用的60余种工具方法</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <html><head></head><body><div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><ul><li><span class="title-icon "></span><a href="#&#x524D;&#x7AEF;js&#x5E38;&#x7528;&#x7684;60&#x4F59;&#x79CD;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;"><b>1.1.1. </b>&#x524D;&#x7AEF;js&#x5E38;&#x7528;&#x7684;60&#x4F59;&#x79CD;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;</a></li></ul></ul></ul></div><a href="#" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h3 id="&#x524D;&#x7AEF;js&#x5E38;&#x7528;&#x7684;60&#x4F59;&#x79CD;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;"><a name="&#x524D;&#x7AEF;js&#x5E38;&#x7528;&#x7684;60&#x4F59;&#x79CD;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x524D;&#x7AEF;js&#x5E38;&#x7528;&#x7684;60&#x4F59;&#x79CD;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.1. &#x524D;&#x7AEF;js&#x5E38;&#x7528;&#x7684;60&#x4F59;&#x79CD;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;</h3>
<blockquote>
<p>&#x201C;&#x5DE5;&#x6B32;&#x5584;&#x5176;&#x4E8B;&#xFF0C;&#x5FC5;&#x5148;&#x5229;&#x5176;&#x5668;&#xFF01;&#x201D;&#x672C;&#x6587;&#x4E3A;&#x5927;&#x5BB6;&#x5E26;&#x6765;&#x524D;&#x7AEF;js&#x5F00;&#x53D1;&#x5E38;&#x7528;&#x7684;60&#x79CD;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;&#xFF0C;&#x6709;&#x4E86;&#x8FD9;&#x4E9B;&#x5F00;&#x53D1;&#x5DE5;&#x5177;&#x4F60;&#x5C31;&#x53EF;&#x4EE5;&#x9AD8;&#x6548;&#x7684;&#x5904;&#x7406;&#x4EFB;&#x52A1;&#x548C;&#x4FE1;&#x606F;&#x4E86;&#x3002;</p>
</blockquote>
<p>1.&#x90AE;&#x7BB1;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isEmail = <span class="hljs-function">(<span class="hljs-params">s</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/</span>.test(s)
}
</code></pre>
<p>2.&#x624B;&#x673A;&#x53F7;&#x7801;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isMobile = <span class="hljs-function">(<span class="hljs-params">s</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^1[0-9]{10}$/</span>.test(s)
}
</code></pre>
<p>3.&#x7535;&#x8BDD;&#x53F7;&#x7801;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isPhone = <span class="hljs-function">(<span class="hljs-params">s</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^([0-9]{3,4}-)?[0-9]{7,8}$/</span>.test(s)
}
</code></pre>
<p>4.&#x662F;&#x5426;url&#x5730;&#x5740;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isURL = <span class="hljs-function">(<span class="hljs-params">s</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^http[s]?:\/\/.*/</span>.test(s)
}
</code></pre>
<p>5.&#x662F;&#x5426;&#x5B57;&#x7B26;&#x4E32;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isString = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;String&apos;</span>
}
</code></pre>
<p>6.&#x662F;&#x5426;&#x6570;&#x5B57;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isNumber = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Number&apos;</span>
}
</code></pre>
<p>7.&#x662F;&#x5426;boolean</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isBoolean = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Boolean&apos;</span>
}
</code></pre>
<p>8.&#x662F;&#x5426;&#x51FD;&#x6570;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isFunction = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Function&apos;</span>
}
</code></pre>
<p>9.&#x662F;&#x5426;&#x4E3A;null</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isNull = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Null&apos;</span>
}
</code></pre>
<p>10.&#x662F;&#x5426;undefined</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isUndefined = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Undefined&apos;</span>
}
</code></pre>
<p>11.&#x662F;&#x5426;&#x5BF9;&#x8C61;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isObj = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Object&apos;</span>
}
</code></pre>
<p>12.&#x662F;&#x5426;&#x6570;&#x7EC4;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isArray = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Array&apos;</span>
}
</code></pre>
<p>13.&#x662F;&#x5426;&#x65F6;&#x95F4;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isDate = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Date&apos;</span>
}
</code></pre>
<p>14.&#x662F;&#x5426;&#x6B63;&#x5219;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isRegExp = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;RegExp&apos;</span>
}
</code></pre>
<p>15.&#x662F;&#x5426;&#x9519;&#x8BEF;&#x5BF9;&#x8C61;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isError = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Error&apos;</span>
}
</code></pre>
<p>16.&#x662F;&#x5426;Symbol&#x51FD;&#x6570;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isSymbol = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Symbol&apos;</span>
}
</code></pre>
<p>17.&#x662F;&#x5426;Promise&#x5BF9;&#x8C61;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isPromise = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Promise&apos;</span>
}
</code></pre>
<p>18.&#x662F;&#x5426;Set&#x5BF9;&#x8C61;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isSet = <span class="hljs-function">(<span class="hljs-params">o</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(o).slice(<span class="hljs-number">8</span>, <span class="hljs-number">-1</span>) === <span class="hljs-string">&apos;Set&apos;</span>
}
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> ua = navigator.userAgent.toLowerCase();
</code></pre>
<p>19.&#x662F;&#x5426;&#x662F;&#x5FAE;&#x4FE1;&#x6D4F;&#x89C8;&#x5668;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isWeiXin = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">return</span> ua.match(<span class="hljs-regexp">/microMessenger/i</span>) == <span class="hljs-string">&apos;micromessenger&apos;</span>
}
</code></pre>
<p>20.&#x662F;&#x5426;&#x662F;&#x79FB;&#x52A8;&#x7AEF;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isDeviceMobile = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-regexp">/android|webos|iphone|ipod|balckberry/i</span>.test(ua)
}
</code></pre>
<p>21.&#x662F;&#x5426;&#x662F;QQ&#x6D4F;&#x89C8;&#x5668;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isQQBrowser = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">return</span> !!ua.match(<span class="hljs-regexp">/mqqbrowser|qzone|qqbrowser|qbwebviewtype/i</span>)
}
</code></pre>
<p>22.&#x662F;&#x5426;&#x662F;&#x722C;&#x866B;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isSpider = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-regexp">/adsbot|googlebot|bingbot|msnbot|yandexbot|baidubot|robot|careerbot|seznambot|bot|baiduspider|jikespider|symantecspider|scannerlwebcrawler|crawler|360spider|sosospider|sogou web sprider|sogou orion spider/</span>.test(ua)
}
</code></pre>
<p>23.&#x662F;&#x5426;ios</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isIos = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">var</span> u = navigator.userAgent;
    <span class="hljs-keyword">if</span> (u.indexOf(<span class="hljs-string">&apos;Android&apos;</span>) &gt; <span class="hljs-number">-1</span> || u.indexOf(<span class="hljs-string">&apos;Linux&apos;</span>) &gt; <span class="hljs-number">-1</span>) {  <span class="hljs-comment">//&#x5B89;&#x5353;&#x624B;&#x673A;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (u.indexOf(<span class="hljs-string">&apos;iPhone&apos;</span>) &gt; <span class="hljs-number">-1</span>) {<span class="hljs-comment">//&#x82F9;&#x679C;&#x624B;&#x673A;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (u.indexOf(<span class="hljs-string">&apos;iPad&apos;</span>) &gt; <span class="hljs-number">-1</span>) {<span class="hljs-comment">//iPad</span>
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (u.indexOf(<span class="hljs-string">&apos;Windows Phone&apos;</span>) &gt; <span class="hljs-number">-1</span>) {<span class="hljs-comment">//winphone&#x624B;&#x673A;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }
}
</code></pre>
<p>24.&#x662F;&#x5426;&#x4E3A;PC&#x7AEF;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isPC = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">var</span> userAgentInfo = navigator.userAgent;
    <span class="hljs-keyword">var</span> Agents = [<span class="hljs-string">&quot;Android&quot;</span>, <span class="hljs-string">&quot;iPhone&quot;</span>,
        <span class="hljs-string">&quot;SymbianOS&quot;</span>, <span class="hljs-string">&quot;Windows Phone&quot;</span>,
        <span class="hljs-string">&quot;iPad&quot;</span>, <span class="hljs-string">&quot;iPod&quot;</span>];
    <span class="hljs-keyword">var</span> flag = <span class="hljs-literal">true</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> v = <span class="hljs-number">0</span>; v &lt; Agents.length; v++) {
        <span class="hljs-keyword">if</span> (userAgentInfo.indexOf(Agents[v]) &gt; <span class="hljs-number">0</span>) {
            flag = <span class="hljs-literal">false</span>;
            <span class="hljs-keyword">break</span>;
        }
    }
    <span class="hljs-keyword">return</span> flag;
}
</code></pre>
<p>25.&#x53BB;&#x9664;html&#x6807;&#x7B7E;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> removeHtmltag = <span class="hljs-function">(<span class="hljs-params">str</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/&lt;[^&gt;]+&gt;/g</span>, <span class="hljs-string">&apos;&apos;</span>)
}
</code></pre>
<p>26.&#x83B7;&#x53D6;url&#x53C2;&#x6570;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getQueryString = <span class="hljs-function">(<span class="hljs-params">name</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> reg = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;(^|&amp;)&apos;</span> + name + <span class="hljs-string">&apos;=([^&amp;]*)(&amp;|$)&apos;</span>, <span class="hljs-string">&apos;i&apos;</span>);
    <span class="hljs-keyword">const</span> search = <span class="hljs-built_in">window</span>.location.search.split(<span class="hljs-string">&apos;?&apos;</span>)[<span class="hljs-number">1</span>] || <span class="hljs-string">&apos;&apos;</span>;
    <span class="hljs-keyword">const</span> r = search.match(reg) || [];
    <span class="hljs-keyword">return</span> r[<span class="hljs-number">2</span>];
}
</code></pre>
<p>27.&#x52A8;&#x6001;&#x5F15;&#x5165;js</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> injectScript = <span class="hljs-function">(<span class="hljs-params">src</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> s = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">&apos;script&apos;</span>);
    s.type = <span class="hljs-string">&apos;text/javascript&apos;</span>;
    s.async = <span class="hljs-literal">true</span>;
    s.src = src;
    <span class="hljs-keyword">const</span> t = <span class="hljs-built_in">document</span>.getElementsByTagName(<span class="hljs-string">&apos;script&apos;</span>)[<span class="hljs-number">0</span>];
    t.parentNode.insertBefore(s, t);
}
</code></pre>
<p>28.&#x6839;&#x636E;url&#x5730;&#x5740;&#x4E0B;&#x8F7D;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> download = <span class="hljs-function">(<span class="hljs-params">url</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> isChrome = navigator.userAgent.toLowerCase().indexOf(<span class="hljs-string">&apos;chrome&apos;</span>) &gt; <span class="hljs-number">-1</span>;
    <span class="hljs-keyword">var</span> isSafari = navigator.userAgent.toLowerCase().indexOf(<span class="hljs-string">&apos;safari&apos;</span>) &gt; <span class="hljs-number">-1</span>;
    <span class="hljs-keyword">if</span> (isChrome || isSafari) {
        <span class="hljs-keyword">var</span> link = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">&apos;a&apos;</span>);
        link.href = url;
        <span class="hljs-keyword">if</span> (link.download !== <span class="hljs-literal">undefined</span>) {
            <span class="hljs-keyword">var</span> fileName = url.substring(url.lastIndexOf(<span class="hljs-string">&apos;/&apos;</span>) + <span class="hljs-number">1</span>, url.length);
            link.download = fileName;
        }
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">document</span>.createEvent) {
            <span class="hljs-keyword">var</span> e = <span class="hljs-built_in">document</span>.createEvent(<span class="hljs-string">&apos;MouseEvents&apos;</span>);
            e.initEvent(<span class="hljs-string">&apos;click&apos;</span>, <span class="hljs-literal">true</span>, <span class="hljs-literal">true</span>);
            link.dispatchEvent(e);
            <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        }
    }
    <span class="hljs-keyword">if</span> (url.indexOf(<span class="hljs-string">&apos;?&apos;</span>) === <span class="hljs-number">-1</span>) {
        url += <span class="hljs-string">&apos;?download&apos;</span>;
    }
    <span class="hljs-built_in">window</span>.open(url, <span class="hljs-string">&apos;_self&apos;</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
</code></pre>
<p>29.el&#x662F;&#x5426;&#x5305;&#x542B;&#x67D0;&#x4E2A;class</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> hasClass = <span class="hljs-function">(<span class="hljs-params">el, className</span>) =&gt;</span> {
    <span class="hljs-keyword">let</span> reg = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;(^|\\s)&apos;</span> + className + <span class="hljs-string">&apos;(\\s|$)&apos;</span>)
    <span class="hljs-keyword">return</span> reg.test(el.className)
}
</code></pre>
<p>30.el&#x6DFB;&#x52A0;&#x67D0;&#x4E2A;class</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> addClass = <span class="hljs-function">(<span class="hljs-params">el, className</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (hasClass(el, className)) {
        <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">let</span> newClass = el.className.split(<span class="hljs-string">&apos; &apos;</span>)
    newClass.push(className)
    el.className = newClass.join(<span class="hljs-string">&apos; &apos;</span>)
}
</code></pre>
<p>31.el&#x53BB;&#x9664;&#x67D0;&#x4E2A;class</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> removeClass = <span class="hljs-function">(<span class="hljs-params">el, className</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (!hasClass(el, className)) {
        <span class="hljs-keyword">return</span>
    }
    <span class="hljs-keyword">let</span> reg = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;(^|\\s)&apos;</span> + className + <span class="hljs-string">&apos;(\\s|$)&apos;</span>, <span class="hljs-string">&apos;g&apos;</span>)
    el.className = el.className.replace(reg, <span class="hljs-string">&apos; &apos;</span>)
}
</code></pre>
<p>32.&#x83B7;&#x53D6;&#x6EDA;&#x52A8;&#x7684;&#x5750;&#x6807;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getScrollPosition = <span class="hljs-function">(<span class="hljs-params">el = <span class="hljs-built_in">window</span></span>) =&gt;</span> ({
    <span class="hljs-attr">x</span>: el.pageXOffset !== <span class="hljs-literal">undefined</span> ? el.pageXOffset : el.scrollLeft,
    <span class="hljs-attr">y</span>: el.pageYOffset !== <span class="hljs-literal">undefined</span> ? el.pageYOffset : el.scrollTop
});
</code></pre>
<p>33.&#x6EDA;&#x52A8;&#x5230;&#x9876;&#x90E8;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> scrollToTop = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">const</span> c = <span class="hljs-built_in">document</span>.documentElement.scrollTop || <span class="hljs-built_in">document</span>.body.scrollTop;
    <span class="hljs-keyword">if</span> (c &gt; <span class="hljs-number">0</span>) {
        <span class="hljs-built_in">window</span>.requestAnimationFrame(scrollToTop);
        <span class="hljs-built_in">window</span>.scrollTo(<span class="hljs-number">0</span>, c - c / <span class="hljs-number">8</span>);
    }
}
</code></pre>
<p>34.el&#x662F;&#x5426;&#x5728;&#x89C6;&#x53E3;&#x8303;&#x56F4;&#x5185;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> elementIsVisibleInViewport = <span class="hljs-function">(<span class="hljs-params">el, partiallyVisible = <span class="hljs-literal">false</span></span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> { top, left, bottom, right } = el.getBoundingClientRect();
    <span class="hljs-keyword">const</span> { innerHeight, innerWidth } = <span class="hljs-built_in">window</span>;
    <span class="hljs-keyword">return</span> partiallyVisible
        ? ((top &gt; <span class="hljs-number">0</span> &amp;&amp; top &lt; innerHeight) || (bottom &gt; <span class="hljs-number">0</span> &amp;&amp; bottom &lt; innerHeight)) &amp;&amp;
        ((left &gt; <span class="hljs-number">0</span> &amp;&amp; left &lt; innerWidth) || (right &gt; <span class="hljs-number">0</span> &amp;&amp; right &lt; innerWidth))
        : top &gt;= <span class="hljs-number">0</span> &amp;&amp; left &gt;= <span class="hljs-number">0</span> &amp;&amp; bottom &lt;= innerHeight &amp;&amp; right &lt;= innerWidth;
}
</code></pre>
<p>35.&#x6D17;&#x724C;&#x7B97;&#x6CD5;&#x968F;&#x673A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> shuffle = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> result = [],
        random;
    <span class="hljs-keyword">while</span> (arr.length &gt; <span class="hljs-number">0</span>) {
        random = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * arr.length);
        result.push(arr[random])
        arr.splice(random, <span class="hljs-number">1</span>)
    }
    <span class="hljs-keyword">return</span> result;
}
</code></pre>
<p>36.&#x52AB;&#x6301;&#x7C98;&#x8D34;&#x677F;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> copyTextToClipboard = <span class="hljs-function">(<span class="hljs-params">value</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> textArea = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">&quot;textarea&quot;</span>);
    textArea.style.background = <span class="hljs-string">&apos;transparent&apos;</span>;
    textArea.value = value;
    <span class="hljs-built_in">document</span>.body.appendChild(textArea);
    textArea.select();
    <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">var</span> successful = <span class="hljs-built_in">document</span>.execCommand(<span class="hljs-string">&apos;copy&apos;</span>);
    } <span class="hljs-keyword">catch</span> (err) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Oops, unable to copy&apos;</span>);
    }
    <span class="hljs-built_in">document</span>.body.removeChild(textArea);
}
</code></pre>
<p>37.&#x5224;&#x65AD;&#x7C7B;&#x578B;&#x96C6;&#x5408;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> checkStr = <span class="hljs-function">(<span class="hljs-params">str, type</span>) =&gt;</span> {
    <span class="hljs-keyword">switch</span> (type) {
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;phone&apos;</span>:   <span class="hljs-comment">//&#x624B;&#x673A;&#x53F7;&#x7801;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^1[3|4|5|6|7|8|9][0-9]{9}$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;tel&apos;</span>:     <span class="hljs-comment">//&#x5EA7;&#x673A;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;card&apos;</span>:    <span class="hljs-comment">//&#x8EAB;&#x4EFD;&#x8BC1;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;pwd&apos;</span>:     <span class="hljs-comment">//&#x5BC6;&#x7801;&#x4EE5;&#x5B57;&#x6BCD;&#x5F00;&#x5934;&#xFF0C;&#x957F;&#x5EA6;&#x5728;6~18&#x4E4B;&#x95F4;&#xFF0C;&#x53EA;&#x80FD;&#x5305;&#x542B;&#x5B57;&#x6BCD;&#x3001;&#x6570;&#x5B57;&#x548C;&#x4E0B;&#x5212;&#x7EBF;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[a-zA-Z]\w{5,17}$/</span>.test(str)
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;postal&apos;</span>:  <span class="hljs-comment">//&#x90AE;&#x653F;&#x7F16;&#x7801;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/[1-9]\d{5}(?!\d)/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;QQ&apos;</span>:      <span class="hljs-comment">//QQ&#x53F7;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[1-9][0-9]{4,9}$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;email&apos;</span>:   <span class="hljs-comment">//&#x90AE;&#x7BB1;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;money&apos;</span>:   <span class="hljs-comment">//&#x91D1;&#x989D;(&#x5C0F;&#x6570;&#x70B9;2&#x4F4D;)</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^\d*(?:\.\d{0,2})?$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;URL&apos;</span>:     <span class="hljs-comment">//&#x7F51;&#x5740;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/</span>.test(str)
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;IP&apos;</span>:      <span class="hljs-comment">//IP</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;date&apos;</span>:    <span class="hljs-comment">//&#x65E5;&#x671F;&#x65F6;&#x95F4;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/</span>.test(str) || <span class="hljs-regexp">/^(\d{4})\-(\d{2})\-(\d{2})$/</span>.test(str)
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;number&apos;</span>:  <span class="hljs-comment">//&#x6570;&#x5B57;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[0-9]$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;english&apos;</span>: <span class="hljs-comment">//&#x82F1;&#x6587;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[a-zA-Z]+$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;chinese&apos;</span>: <span class="hljs-comment">//&#x4E2D;&#x6587;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[\\u4E00-\\u9FA5]+$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;lower&apos;</span>:   <span class="hljs-comment">//&#x5C0F;&#x5199;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[a-z]+$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;upper&apos;</span>:   <span class="hljs-comment">//&#x5927;&#x5199;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/^[A-Z]+$/</span>.test(str);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;HTML&apos;</span>:    <span class="hljs-comment">//HTML&#x6807;&#x8BB0;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-regexp">/&lt;(&quot;[^&quot;]*&quot;|&apos;[^&apos;]*&apos;|[^&apos;&quot;&gt;])*&gt;/</span>.test(str);
        <span class="hljs-keyword">default</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
}
</code></pre>
<p>38.&#x4E25;&#x683C;&#x7684;&#x8EAB;&#x4EFD;&#x8BC1;&#x6821;&#x9A8C;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isCardID = <span class="hljs-function">(<span class="hljs-params">sId</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (!<span class="hljs-regexp">/(^\d{15}$)|(^\d{17}(\d|X|x)$)/</span>.test(sId)) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x4F60;&#x8F93;&#x5165;&#x7684;&#x8EAB;&#x4EFD;&#x8BC1;&#x957F;&#x5EA6;&#x6216;&#x683C;&#x5F0F;&#x9519;&#x8BEF;&apos;</span>)
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }
    <span class="hljs-comment">//&#x8EAB;&#x4EFD;&#x8BC1;&#x57CE;&#x5E02;</span>
    <span class="hljs-keyword">var</span> aCity = { <span class="hljs-number">11</span>: <span class="hljs-string">&quot;&#x5317;&#x4EAC;&quot;</span>, <span class="hljs-number">12</span>: <span class="hljs-string">&quot;&#x5929;&#x6D25;&quot;</span>, <span class="hljs-number">13</span>: <span class="hljs-string">&quot;&#x6CB3;&#x5317;&quot;</span>, <span class="hljs-number">14</span>: <span class="hljs-string">&quot;&#x5C71;&#x897F;&quot;</span>, <span class="hljs-number">15</span>: <span class="hljs-string">&quot;&#x5185;&#x8499;&#x53E4;&quot;</span>, <span class="hljs-number">21</span>: <span class="hljs-string">&quot;&#x8FBD;&#x5B81;&quot;</span>, <span class="hljs-number">22</span>: <span class="hljs-string">&quot;&#x5409;&#x6797;&quot;</span>, <span class="hljs-number">23</span>: <span class="hljs-string">&quot;&#x9ED1;&#x9F99;&#x6C5F;&quot;</span>, <span class="hljs-number">31</span>: <span class="hljs-string">&quot;&#x4E0A;&#x6D77;&quot;</span>, <span class="hljs-number">32</span>: <span class="hljs-string">&quot;&#x6C5F;&#x82CF;&quot;</span>, <span class="hljs-number">33</span>: <span class="hljs-string">&quot;&#x6D59;&#x6C5F;&quot;</span>, <span class="hljs-number">34</span>: <span class="hljs-string">&quot;&#x5B89;&#x5FBD;&quot;</span>, <span class="hljs-number">35</span>: <span class="hljs-string">&quot;&#x798F;&#x5EFA;&quot;</span>, <span class="hljs-number">36</span>: <span class="hljs-string">&quot;&#x6C5F;&#x897F;&quot;</span>, <span class="hljs-number">37</span>: <span class="hljs-string">&quot;&#x5C71;&#x4E1C;&quot;</span>, <span class="hljs-number">41</span>: <span class="hljs-string">&quot;&#x6CB3;&#x5357;&quot;</span>, <span class="hljs-number">42</span>: <span class="hljs-string">&quot;&#x6E56;&#x5317;&quot;</span>, <span class="hljs-number">43</span>: <span class="hljs-string">&quot;&#x6E56;&#x5357;&quot;</span>, <span class="hljs-number">44</span>: <span class="hljs-string">&quot;&#x5E7F;&#x4E1C;&quot;</span>, <span class="hljs-number">45</span>: <span class="hljs-string">&quot;&#x5E7F;&#x897F;&quot;</span>, <span class="hljs-number">46</span>: <span class="hljs-string">&quot;&#x6D77;&#x5357;&quot;</span>, <span class="hljs-number">50</span>: <span class="hljs-string">&quot;&#x91CD;&#x5E86;&quot;</span>, <span class="hljs-number">51</span>: <span class="hljs-string">&quot;&#x56DB;&#x5DDD;&quot;</span>, <span class="hljs-number">52</span>: <span class="hljs-string">&quot;&#x8D35;&#x5DDE;&quot;</span>, <span class="hljs-number">53</span>: <span class="hljs-string">&quot;&#x4E91;&#x5357;&quot;</span>, <span class="hljs-number">54</span>: <span class="hljs-string">&quot;&#x897F;&#x85CF;&quot;</span>, <span class="hljs-number">61</span>: <span class="hljs-string">&quot;&#x9655;&#x897F;&quot;</span>, <span class="hljs-number">62</span>: <span class="hljs-string">&quot;&#x7518;&#x8083;&quot;</span>, <span class="hljs-number">63</span>: <span class="hljs-string">&quot;&#x9752;&#x6D77;&quot;</span>, <span class="hljs-number">64</span>: <span class="hljs-string">&quot;&#x5B81;&#x590F;&quot;</span>, <span class="hljs-number">65</span>: <span class="hljs-string">&quot;&#x65B0;&#x7586;&quot;</span>, <span class="hljs-number">71</span>: <span class="hljs-string">&quot;&#x53F0;&#x6E7E;&quot;</span>, <span class="hljs-number">81</span>: <span class="hljs-string">&quot;&#x9999;&#x6E2F;&quot;</span>, <span class="hljs-number">82</span>: <span class="hljs-string">&quot;&#x6FB3;&#x95E8;&quot;</span>, <span class="hljs-number">91</span>: <span class="hljs-string">&quot;&#x56FD;&#x5916;&quot;</span> };
    <span class="hljs-keyword">if</span> (!aCity[<span class="hljs-built_in">parseInt</span>(sId.substr(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>))]) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x4F60;&#x7684;&#x8EAB;&#x4EFD;&#x8BC1;&#x5730;&#x533A;&#x975E;&#x6CD5;&apos;</span>)
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }

    <span class="hljs-comment">// &#x51FA;&#x751F;&#x65E5;&#x671F;&#x9A8C;&#x8BC1;</span>
    <span class="hljs-keyword">var</span> sBirthday = (sId.substr(<span class="hljs-number">6</span>, <span class="hljs-number">4</span>) + <span class="hljs-string">&quot;-&quot;</span> + <span class="hljs-built_in">Number</span>(sId.substr(<span class="hljs-number">10</span>, <span class="hljs-number">2</span>)) + <span class="hljs-string">&quot;-&quot;</span> + <span class="hljs-built_in">Number</span>(sId.substr(<span class="hljs-number">12</span>, <span class="hljs-number">2</span>))).replace(<span class="hljs-regexp">/-/g</span>, <span class="hljs-string">&quot;/&quot;</span>),
        d = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(sBirthday)
    <span class="hljs-keyword">if</span> (sBirthday != (d.getFullYear() + <span class="hljs-string">&quot;/&quot;</span> + (d.getMonth() + <span class="hljs-number">1</span>) + <span class="hljs-string">&quot;/&quot;</span> + d.getDate())) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x4E0A;&#x7684;&#x51FA;&#x751F;&#x65E5;&#x671F;&#x975E;&#x6CD5;&apos;</span>)
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }

    <span class="hljs-comment">// &#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&#x7801;&#x6821;&#x9A8C;</span>
    <span class="hljs-keyword">var</span> sum = <span class="hljs-number">0</span>,
        weights = [<span class="hljs-number">7</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>, <span class="hljs-number">5</span>, <span class="hljs-number">8</span>, <span class="hljs-number">4</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">6</span>, <span class="hljs-number">3</span>, <span class="hljs-number">7</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>, <span class="hljs-number">5</span>, <span class="hljs-number">8</span>, <span class="hljs-number">4</span>, <span class="hljs-number">2</span>],
        codes = <span class="hljs-string">&quot;10X98765432&quot;</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; sId.length - <span class="hljs-number">1</span>; i++) {
        sum += sId[i] * weights[i];
    }
    <span class="hljs-keyword">var</span> last = codes[sum % <span class="hljs-number">11</span>]; <span class="hljs-comment">//&#x8BA1;&#x7B97;&#x51FA;&#x6765;&#x7684;&#x6700;&#x540E;&#x4E00;&#x4F4D;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&#x7801;</span>
    <span class="hljs-keyword">if</span> (sId[sId.length - <span class="hljs-number">1</span>] != last) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x4F60;&#x8F93;&#x5165;&#x7684;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&#x975E;&#x6CD5;&apos;</span>)
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }

    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
}
</code></pre>
<p>39.&#x968F;&#x673A;&#x6570;&#x8303;&#x56F4;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> random = <span class="hljs-function">(<span class="hljs-params">min, max</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">arguments</span>.length === <span class="hljs-number">2</span>) {
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.floor(min + <span class="hljs-built_in">Math</span>.random() * ((max + <span class="hljs-number">1</span>) - min))
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
    }
}
</code></pre>
<p>40.&#x5C06;&#x963F;&#x62C9;&#x4F2F;&#x6570;&#x5B57;&#x7FFB;&#x8BD1;&#x6210;&#x4E2D;&#x6587;&#x7684;&#x5927;&#x5199;&#x6570;&#x5B57;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> numberToChinese = <span class="hljs-function">(<span class="hljs-params">num</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> AA = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(<span class="hljs-string">&quot;&#x96F6;&quot;</span>, <span class="hljs-string">&quot;&#x4E00;&quot;</span>, <span class="hljs-string">&quot;&#x4E8C;&quot;</span>, <span class="hljs-string">&quot;&#x4E09;&quot;</span>, <span class="hljs-string">&quot;&#x56DB;&quot;</span>, <span class="hljs-string">&quot;&#x4E94;&quot;</span>, <span class="hljs-string">&quot;&#x516D;&quot;</span>, <span class="hljs-string">&quot;&#x4E03;&quot;</span>, <span class="hljs-string">&quot;&#x516B;&quot;</span>, <span class="hljs-string">&quot;&#x4E5D;&quot;</span>, <span class="hljs-string">&quot;&#x5341;&quot;</span>);
    <span class="hljs-keyword">var</span> BB = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(<span class="hljs-string">&quot;&quot;</span>, <span class="hljs-string">&quot;&#x5341;&quot;</span>, <span class="hljs-string">&quot;&#x767E;&quot;</span>, <span class="hljs-string">&quot;&#x4EDF;&quot;</span>, <span class="hljs-string">&quot;&#x842C;&quot;</span>, <span class="hljs-string">&quot;&#x5104;&quot;</span>, <span class="hljs-string">&quot;&#x70B9;&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);
    <span class="hljs-keyword">var</span> a = (<span class="hljs-string">&quot;&quot;</span> + num).replace(<span class="hljs-regexp">/(^0*)/g</span>, <span class="hljs-string">&quot;&quot;</span>).split(<span class="hljs-string">&quot;.&quot;</span>),
        k = <span class="hljs-number">0</span>,
        re = <span class="hljs-string">&quot;&quot;</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = a[<span class="hljs-number">0</span>].length - <span class="hljs-number">1</span>; i &gt;= <span class="hljs-number">0</span>; i--) {
        <span class="hljs-keyword">switch</span> (k) {
            <span class="hljs-keyword">case</span> <span class="hljs-number">0</span>:
                re = BB[<span class="hljs-number">7</span>] + re;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">4</span>:
                <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&quot;0{4}//d{&quot;</span> + (a[<span class="hljs-number">0</span>].length - i - <span class="hljs-number">1</span>) + <span class="hljs-string">&quot;}$&quot;</span>)
                    .test(a[<span class="hljs-number">0</span>]))
                    re = BB[<span class="hljs-number">4</span>] + re;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">8</span>:
                re = BB[<span class="hljs-number">5</span>] + re;
                BB[<span class="hljs-number">7</span>] = BB[<span class="hljs-number">5</span>];
                k = <span class="hljs-number">0</span>;
                <span class="hljs-keyword">break</span>;
        }
        <span class="hljs-keyword">if</span> (k % <span class="hljs-number">4</span> == <span class="hljs-number">2</span> &amp;&amp; a[<span class="hljs-number">0</span>].charAt(i + <span class="hljs-number">2</span>) != <span class="hljs-number">0</span> &amp;&amp; a[<span class="hljs-number">0</span>].charAt(i + <span class="hljs-number">1</span>) == <span class="hljs-number">0</span>)
            re = AA[<span class="hljs-number">0</span>] + re;
        <span class="hljs-keyword">if</span> (a[<span class="hljs-number">0</span>].charAt(i) != <span class="hljs-number">0</span>)
            re = AA[a[<span class="hljs-number">0</span>].charAt(i)] + BB[k % <span class="hljs-number">4</span>] + re;
        k++;
    }

    <span class="hljs-keyword">if</span> (a.length &gt; <span class="hljs-number">1</span>) <span class="hljs-comment">// &#x52A0;&#x4E0A;&#x5C0F;&#x6570;&#x90E8;&#x5206;(&#x5982;&#x679C;&#x6709;&#x5C0F;&#x6570;&#x90E8;&#x5206;)</span>
    {
        re += BB[<span class="hljs-number">6</span>];
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; a[<span class="hljs-number">1</span>].length; i++)
            re += AA[a[<span class="hljs-number">1</span>].charAt(i)];
    }
    <span class="hljs-keyword">if</span> (re == <span class="hljs-string">&apos;&#x4E00;&#x5341;&apos;</span>)
        re = <span class="hljs-string">&quot;&#x5341;&quot;</span>;
    <span class="hljs-keyword">if</span> (re.match(<span class="hljs-regexp">/^&#x4E00;/</span>) &amp;&amp; re.length == <span class="hljs-number">3</span>)
        re = re.replace(<span class="hljs-string">&quot;&#x4E00;&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);
    <span class="hljs-keyword">return</span> re;
}
</code></pre>
<p>41.&#x5C06;&#x6570;&#x5B57;&#x8F6C;&#x6362;&#x4E3A;&#x5927;&#x5199;&#x91D1;&#x989D;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> changeToChinese = <span class="hljs-function">(<span class="hljs-params">Num</span>) =&gt;</span> {
    <span class="hljs-comment">//&#x5224;&#x65AD;&#x5982;&#x679C;&#x4F20;&#x9012;&#x8FDB;&#x6765;&#x7684;&#x4E0D;&#x662F;&#x5B57;&#x7B26;&#x7684;&#x8BDD;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> Num == <span class="hljs-string">&quot;number&quot;</span>) {
        Num = <span class="hljs-keyword">new</span> <span class="hljs-built_in">String</span>(Num);
    };
    Num = Num.replace(<span class="hljs-regexp">/,/g</span>, <span class="hljs-string">&quot;&quot;</span>) <span class="hljs-comment">//&#x66FF;&#x6362;tomoney()&#x4E2D;&#x7684;&#x201C;,&#x201D;</span>
    Num = Num.replace(<span class="hljs-regexp">/ /g</span>, <span class="hljs-string">&quot;&quot;</span>) <span class="hljs-comment">//&#x66FF;&#x6362;tomoney()&#x4E2D;&#x7684;&#x7A7A;&#x683C;</span>
    Num = Num.replace(<span class="hljs-regexp">/&#xFFE5;/g</span>, <span class="hljs-string">&quot;&quot;</span>) <span class="hljs-comment">//&#x66FF;&#x6362;&#x6389;&#x53EF;&#x80FD;&#x51FA;&#x73B0;&#x7684;&#xFFE5;&#x5B57;&#x7B26;</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">isNaN</span>(Num)) { <span class="hljs-comment">//&#x9A8C;&#x8BC1;&#x8F93;&#x5165;&#x7684;&#x5B57;&#x7B26;&#x662F;&#x5426;&#x4E3A;&#x6570;&#x5B57;</span>
        <span class="hljs-comment">//alert(&quot;&#x8BF7;&#x68C0;&#x67E5;&#x5C0F;&#x5199;&#x91D1;&#x989D;&#x662F;&#x5426;&#x6B63;&#x786E;&quot;);</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>;
    };
    <span class="hljs-comment">//&#x5B57;&#x7B26;&#x5904;&#x7406;&#x5B8C;&#x6BD5;&#x540E;&#x5F00;&#x59CB;&#x8F6C;&#x6362;&#xFF0C;&#x91C7;&#x7528;&#x524D;&#x540E;&#x4E24;&#x90E8;&#x5206;&#x5206;&#x522B;&#x8F6C;&#x6362;</span>
    <span class="hljs-keyword">var</span> part = <span class="hljs-built_in">String</span>(Num).split(<span class="hljs-string">&quot;.&quot;</span>);
    <span class="hljs-keyword">var</span> newchar = <span class="hljs-string">&quot;&quot;</span>;
    <span class="hljs-comment">//&#x5C0F;&#x6570;&#x70B9;&#x524D;&#x8FDB;&#x884C;&#x8F6C;&#x5316;</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = part[<span class="hljs-number">0</span>].length - <span class="hljs-number">1</span>; i &gt;= <span class="hljs-number">0</span>; i--) {
        <span class="hljs-keyword">if</span> (part[<span class="hljs-number">0</span>].length &gt; <span class="hljs-number">10</span>) {
            <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>;
            <span class="hljs-comment">//&#x82E5;&#x6570;&#x91CF;&#x8D85;&#x8FC7;&#x62FE;&#x4EBF;&#x5355;&#x4F4D;&#xFF0C;&#x63D0;&#x793A;</span>
        }
        <span class="hljs-keyword">var</span> tmpnewchar = <span class="hljs-string">&quot;&quot;</span>
        <span class="hljs-keyword">var</span> perchar = part[<span class="hljs-number">0</span>].charAt(i);
        <span class="hljs-keyword">switch</span> (perchar) {
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;0&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x96F6;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;1&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x58F9;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;2&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x8D30;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;3&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x53C1;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;4&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x8086;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;5&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x4F0D;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;6&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x9646;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;7&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x67D2;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;8&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x634C;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;9&quot;</span>:
                tmpnewchar = <span class="hljs-string">&quot;&#x7396;&quot;</span> + tmpnewchar;
                <span class="hljs-keyword">break</span>;
        }
        <span class="hljs-keyword">switch</span> (part[<span class="hljs-number">0</span>].length - i - <span class="hljs-number">1</span>) {
            <span class="hljs-keyword">case</span> <span class="hljs-number">0</span>:
                tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x5143;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
                <span class="hljs-keyword">if</span> (perchar != <span class="hljs-number">0</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x62FE;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
                <span class="hljs-keyword">if</span> (perchar != <span class="hljs-number">0</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x4F70;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:
                <span class="hljs-keyword">if</span> (perchar != <span class="hljs-number">0</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x4EDF;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">4</span>:
                tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x4E07;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">5</span>:
                <span class="hljs-keyword">if</span> (perchar != <span class="hljs-number">0</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x62FE;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">6</span>:
                <span class="hljs-keyword">if</span> (perchar != <span class="hljs-number">0</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x4F70;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">7</span>:
                <span class="hljs-keyword">if</span> (perchar != <span class="hljs-number">0</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x4EDF;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">8</span>:
                tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x4EBF;&quot;</span>;
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-number">9</span>:
                tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x62FE;&quot;</span>;
                <span class="hljs-keyword">break</span>;
        }
        <span class="hljs-keyword">var</span> newchar = tmpnewchar + newchar;
    }
    <span class="hljs-comment">//&#x5C0F;&#x6570;&#x70B9;&#x4E4B;&#x540E;&#x8FDB;&#x884C;&#x8F6C;&#x5316;</span>
    <span class="hljs-keyword">if</span> (Num.indexOf(<span class="hljs-string">&quot;.&quot;</span>) != <span class="hljs-number">-1</span>) {
        <span class="hljs-keyword">if</span> (part[<span class="hljs-number">1</span>].length &gt; <span class="hljs-number">2</span>) {
            <span class="hljs-comment">// alert(&quot;&#x5C0F;&#x6570;&#x70B9;&#x4E4B;&#x540E;&#x53EA;&#x80FD;&#x4FDD;&#x7559;&#x4E24;&#x4F4D;,&#x7CFB;&#x7EDF;&#x5C06;&#x81EA;&#x52A8;&#x622A;&#x65AD;&quot;);</span>
            part[<span class="hljs-number">1</span>] = part[<span class="hljs-number">1</span>].substr(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>)
        }
        <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; part[<span class="hljs-number">1</span>].length; i++) {
            tmpnewchar = <span class="hljs-string">&quot;&quot;</span>
            perchar = part[<span class="hljs-number">1</span>].charAt(i)
            <span class="hljs-keyword">switch</span> (perchar) {
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;0&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x96F6;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;1&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x58F9;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;2&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x8D30;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;3&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x53C1;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;4&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x8086;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;5&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x4F0D;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;6&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x9646;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;7&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x67D2;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;8&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x634C;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;9&quot;</span>:
                    tmpnewchar = <span class="hljs-string">&quot;&#x7396;&quot;</span> + tmpnewchar;
                    <span class="hljs-keyword">break</span>;
            }
            <span class="hljs-keyword">if</span> (i == <span class="hljs-number">0</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x89D2;&quot;</span>;
            <span class="hljs-keyword">if</span> (i == <span class="hljs-number">1</span>) tmpnewchar = tmpnewchar + <span class="hljs-string">&quot;&#x5206;&quot;</span>;
            newchar = newchar + tmpnewchar;
        }
    }
    <span class="hljs-comment">//&#x66FF;&#x6362;&#x6240;&#x6709;&#x65E0;&#x7528;&#x6C49;&#x5B57;</span>
    <span class="hljs-keyword">while</span> (newchar.search(<span class="hljs-string">&quot;&#x96F6;&#x96F6;&quot;</span>) != <span class="hljs-number">-1</span>)
        newchar = newchar.replace(<span class="hljs-string">&quot;&#x96F6;&#x96F6;&quot;</span>, <span class="hljs-string">&quot;&#x96F6;&quot;</span>);
    newchar = newchar.replace(<span class="hljs-string">&quot;&#x96F6;&#x4EBF;&quot;</span>, <span class="hljs-string">&quot;&#x4EBF;&quot;</span>);
    newchar = newchar.replace(<span class="hljs-string">&quot;&#x4EBF;&#x4E07;&quot;</span>, <span class="hljs-string">&quot;&#x4EBF;&quot;</span>);
    newchar = newchar.replace(<span class="hljs-string">&quot;&#x96F6;&#x4E07;&quot;</span>, <span class="hljs-string">&quot;&#x4E07;&quot;</span>);
    newchar = newchar.replace(<span class="hljs-string">&quot;&#x96F6;&#x5143;&quot;</span>, <span class="hljs-string">&quot;&#x5143;&quot;</span>);
    newchar = newchar.replace(<span class="hljs-string">&quot;&#x96F6;&#x89D2;&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);
    newchar = newchar.replace(<span class="hljs-string">&quot;&#x96F6;&#x5206;&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);
    <span class="hljs-keyword">if</span> (newchar.charAt(newchar.length - <span class="hljs-number">1</span>) == <span class="hljs-string">&quot;&#x5143;&quot;</span>) {
        newchar = newchar + <span class="hljs-string">&quot;&#x6574;&quot;</span>
    }
    <span class="hljs-keyword">return</span> newchar;
}
</code></pre>
<p>42.&#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x662F;&#x5426;&#x5728;&#x6570;&#x7EC4;&#x4E2D;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> contains = <span class="hljs-function">(<span class="hljs-params">arr, val</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> arr.indexOf(val) != <span class="hljs-number">-1</span> ? <span class="hljs-literal">true</span> : <span class="hljs-literal">false</span>;
}
</code></pre>
<p>43.&#x6570;&#x7EC4;&#x6392;&#x5E8F;&#xFF0C;<code>{type} 1&#xFF1A;&#x4ECE;&#x5C0F;&#x5230;&#x5927; 2&#xFF1A;&#x4ECE;&#x5927;&#x5230;&#x5C0F; 3&#xFF1A;&#x968F;&#x673A;</code></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> sort = <span class="hljs-function">(<span class="hljs-params">arr, type = <span class="hljs-number">1</span></span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> arr.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
        <span class="hljs-keyword">switch</span> (type) {
            <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
                <span class="hljs-keyword">return</span> a - b;
            <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
                <span class="hljs-keyword">return</span> b - a;
            <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:
                <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.random() - <span class="hljs-number">0.5</span>;
            <span class="hljs-keyword">default</span>:
                <span class="hljs-keyword">return</span> arr;
        }
    })
}
</code></pre>
<p>44.&#x53BB;&#x91CD;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> unique = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Array</span>.hasOwnProperty(<span class="hljs-string">&apos;from&apos;</span>)) {
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">Array</span>.from(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arr));
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">var</span> n = {}, r = [];
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; arr.length; i++) {
            <span class="hljs-keyword">if</span> (!n[arr[i]]) {
                n[arr[i]] = <span class="hljs-literal">true</span>;
                r.push(arr[i]);
            }
        }
        <span class="hljs-keyword">return</span> r;
    }
}
</code></pre>
<p>45.&#x6C42;&#x4E24;&#x4E2A;&#x96C6;&#x5408;&#x7684;&#x5E76;&#x96C6;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> union = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> newArr = a.concat(b);
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.unique(newArr);
}
</code></pre>
<p>46.&#x6C42;&#x4E24;&#x4E2A;&#x96C6;&#x5408;&#x7684;&#x4EA4;&#x96C6;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> intersect = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> _this = <span class="hljs-keyword">this</span>;
    a = <span class="hljs-keyword">this</span>.unique(a);
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.map(a, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">o</span>) </span>{
        <span class="hljs-keyword">return</span> _this.contains(b, o) ? o : <span class="hljs-literal">null</span>;
    });
}
</code></pre>
<p>47.&#x5220;&#x9664;&#x5176;&#x4E2D;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> remove = <span class="hljs-function">(<span class="hljs-params">arr, ele</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> index = arr.indexOf(ele);
    <span class="hljs-keyword">if</span> (index &gt; <span class="hljs-number">-1</span>) {
        arr.splice(index, <span class="hljs-number">1</span>);
    }
    <span class="hljs-keyword">return</span> arr;
}
</code></pre>
<p>48.&#x5C06;&#x7C7B;&#x6570;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x7EC4;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> formArray = <span class="hljs-function">(<span class="hljs-params">ary</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> arr = [];
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Array</span>.isArray(ary)) {
        arr = ary;
    } <span class="hljs-keyword">else</span> {
        arr = <span class="hljs-built_in">Array</span>.prototype.slice.call(ary);
    };
    <span class="hljs-keyword">return</span> arr;
}
</code></pre>
<p>49.&#x6700;&#x5927;&#x503C;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> max = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.max.apply(<span class="hljs-literal">null</span>, arr);
}
</code></pre>
<p>50.&#x6700;&#x5C0F;&#x503C;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> min = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Math</span>.min.apply(<span class="hljs-literal">null</span>, arr);
}
</code></pre>
<p>51.&#x6C42;&#x548C;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> sum = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> arr.reduce(<span class="hljs-function">(<span class="hljs-params">pre, cur</span>) =&gt;</span> {
        <span class="hljs-keyword">return</span> pre + cur
    })
}
</code></pre>
<p>52.&#x5E73;&#x5747;&#x503C;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> average = <span class="hljs-function">(<span class="hljs-params">arr</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.sum(arr) / arr.length
}
</code></pre>
<p>53.&#x53BB;&#x9664;&#x7A7A;&#x683C;,<code>type: 1-&#x6240;&#x6709;&#x7A7A;&#x683C; 2-&#x524D;&#x540E;&#x7A7A;&#x683C; 3-&#x524D;&#x7A7A;&#x683C; 4-&#x540E;&#x7A7A;&#x683C;</code></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> trim = <span class="hljs-function">(<span class="hljs-params">str, type</span>) =&gt;</span> {
    type = type || <span class="hljs-number">1</span>
    <span class="hljs-keyword">switch</span> (type) {
        <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
            <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/\s+/g</span>, <span class="hljs-string">&quot;&quot;</span>);
        <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
            <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/(^\s*)|(\s*$)/g</span>, <span class="hljs-string">&quot;&quot;</span>);
        <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:
            <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/(^\s*)/g</span>, <span class="hljs-string">&quot;&quot;</span>);
        <span class="hljs-keyword">case</span> <span class="hljs-number">4</span>:
            <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/(\s*$)/g</span>, <span class="hljs-string">&quot;&quot;</span>);
        <span class="hljs-keyword">default</span>:
            <span class="hljs-keyword">return</span> str;
    }
}
</code></pre>
<p>54.&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#xFF0C;<code>type: 1:&#x9996;&#x5B57;&#x6BCD;&#x5927;&#x5199; 2&#xFF1A;&#x9996;&#x5B57;&#x6BCD;&#x5C0F;&#x5199; 3&#xFF1A;&#x5927;&#x5C0F;&#x5199;&#x8F6C;&#x6362; 4&#xFF1A;&#x5168;&#x90E8;&#x5927;&#x5199; 5&#xFF1A;&#x5168;&#x90E8;&#x5C0F;&#x5199;</code></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> changeCase = <span class="hljs-function">(<span class="hljs-params">str, type</span>) =&gt;</span> {
    type = type || <span class="hljs-number">4</span>
    <span class="hljs-keyword">switch</span> (type) {
        <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
            <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/\b\w+\b/g</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">word</span>) </span>{
                <span class="hljs-keyword">return</span> word.substring(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>).toUpperCase() + word.substring(<span class="hljs-number">1</span>).toLowerCase();

            });
        <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
            <span class="hljs-keyword">return</span> str.replace(<span class="hljs-regexp">/\b\w+\b/g</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">word</span>) </span>{
                <span class="hljs-keyword">return</span> word.substring(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>).toLowerCase() + word.substring(<span class="hljs-number">1</span>).toUpperCase();
            });
        <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:
            <span class="hljs-keyword">return</span> str.split(<span class="hljs-string">&apos;&apos;</span>).map(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">word</span>) </span>{
                <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/[a-z]/</span>.test(word)) {
                    <span class="hljs-keyword">return</span> word.toUpperCase();
                } <span class="hljs-keyword">else</span> {
                    <span class="hljs-keyword">return</span> word.toLowerCase()
                }
            }).join(<span class="hljs-string">&apos;&apos;</span>)
        <span class="hljs-keyword">case</span> <span class="hljs-number">4</span>:
            <span class="hljs-keyword">return</span> str.toUpperCase();
        <span class="hljs-keyword">case</span> <span class="hljs-number">5</span>:
            <span class="hljs-keyword">return</span> str.toLowerCase();
        <span class="hljs-keyword">default</span>:
            <span class="hljs-keyword">return</span> str;
    }
}
</code></pre>
<p>55.&#x68C0;&#x6D4B;&#x5BC6;&#x7801;&#x5F3A;&#x5EA6;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> checkPwd = <span class="hljs-function">(<span class="hljs-params">str</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> Lv = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">if</span> (str.length &lt; <span class="hljs-number">6</span>) {
        <span class="hljs-keyword">return</span> Lv
    }
    <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/[0-9]/</span>.test(str)) {
        Lv++
    }
    <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/[a-z]/</span>.test(str)) {
        Lv++
    }
    <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/[A-Z]/</span>.test(str)) {
        Lv++
    }
    <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/[\.|-|_]/</span>.test(str)) {
        Lv++
    }
    <span class="hljs-keyword">return</span> Lv;
}
</code></pre>
<p>56.&#x51FD;&#x6570;&#x8282;&#x6D41;&#x5668;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> debouncer = <span class="hljs-function">(<span class="hljs-params">fn, time, interval = <span class="hljs-number">200</span></span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (time - (<span class="hljs-built_in">window</span>.debounceTimestamp || <span class="hljs-number">0</span>) &gt; interval) {
        fn &amp;&amp; fn();
        <span class="hljs-built_in">window</span>.debounceTimestamp = time;
    }
}
</code></pre>
<p>57.&#x5728;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x63D2;&#x5165;&#x65B0;&#x5B57;&#x7B26;&#x4E32;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> insertStr = <span class="hljs-function">(<span class="hljs-params">soure, index, newStr</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> str = soure.slice(<span class="hljs-number">0</span>, index) + newStr + soure.slice(index);
    <span class="hljs-keyword">return</span> str;
}
</code></pre>
<p>58.&#x5224;&#x65AD;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x952E;&#x503C;&#x76F8;&#x540C;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> isObjectEqual = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> aProps = <span class="hljs-built_in">Object</span>.getOwnPropertyNames(a);
    <span class="hljs-keyword">var</span> bProps = <span class="hljs-built_in">Object</span>.getOwnPropertyNames(b);

    <span class="hljs-keyword">if</span> (aProps.length !== bProps.length) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; aProps.length; i++) {
        <span class="hljs-keyword">var</span> propName = aProps[i];

        <span class="hljs-keyword">if</span> (a[propName] !== b[propName]) {
            <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
</code></pre>
<p>59.16&#x8FDB;&#x5236;&#x989C;&#x8272;&#x8F6C;RGBRGBA&#x5B57;&#x7B26;&#x4E32;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> colorToRGB = <span class="hljs-function">(<span class="hljs-params">val, opa</span>) =&gt;</span> {

    <span class="hljs-keyword">var</span> pattern = <span class="hljs-regexp">/^(#?)[a-fA-F0-9]{6}$/</span>; <span class="hljs-comment">//16&#x8FDB;&#x5236;&#x989C;&#x8272;&#x503C;&#x6821;&#x9A8C;&#x89C4;&#x5219;</span>
    <span class="hljs-keyword">var</span> isOpa = <span class="hljs-keyword">typeof</span> opa == <span class="hljs-string">&apos;number&apos;</span>; <span class="hljs-comment">//&#x5224;&#x65AD;&#x662F;&#x5426;&#x6709;&#x8BBE;&#x7F6E;&#x4E0D;&#x900F;&#x660E;&#x5EA6;</span>

    <span class="hljs-keyword">if</span> (!pattern.test(val)) { <span class="hljs-comment">//&#x5982;&#x679C;&#x503C;&#x4E0D;&#x7B26;&#x5408;&#x89C4;&#x5219;&#x8FD4;&#x56DE;&#x7A7A;&#x5B57;&#x7B26;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&apos;</span>;
    }

    <span class="hljs-keyword">var</span> v = val.replace(<span class="hljs-regexp">/#/</span>, <span class="hljs-string">&apos;&apos;</span>); <span class="hljs-comment">//&#x5982;&#x679C;&#x6709;#&#x53F7;&#x5148;&#x53BB;&#x9664;#&#x53F7;</span>
    <span class="hljs-keyword">var</span> rgbArr = [];
    <span class="hljs-keyword">var</span> rgbStr = <span class="hljs-string">&apos;&apos;</span>;

    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; i++) {
        <span class="hljs-keyword">var</span> item = v.substring(i * <span class="hljs-number">2</span>, i * <span class="hljs-number">2</span> + <span class="hljs-number">2</span>);
        <span class="hljs-keyword">var</span> num = <span class="hljs-built_in">parseInt</span>(item, <span class="hljs-number">16</span>);
        rgbArr.push(num);
    }

    rgbStr = rgbArr.join();
    rgbStr = <span class="hljs-string">&apos;rgb&apos;</span> + (isOpa ? <span class="hljs-string">&apos;a&apos;</span> : <span class="hljs-string">&apos;&apos;</span>) + <span class="hljs-string">&apos;(&apos;</span> + rgbStr + (isOpa ? <span class="hljs-string">&apos;,&apos;</span> + opa : <span class="hljs-string">&apos;&apos;</span>) + <span class="hljs-string">&apos;)&apos;</span>;
    <span class="hljs-keyword">return</span> rgbStr;
}
</code></pre>
<p>60.&#x8FFD;&#x52A0;url&#x53C2;&#x6570;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> appendQuery = <span class="hljs-function">(<span class="hljs-params">url, key, value</span>) =&gt;</span> {
    <span class="hljs-keyword">var</span> options = key;
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> options == <span class="hljs-string">&apos;string&apos;</span>) {
        options = {};
        options[key] = value;
    }
    options = $.param(options);
    <span class="hljs-keyword">if</span> (url.includes(<span class="hljs-string">&apos;?&apos;</span>)) {
        url += <span class="hljs-string">&apos;&amp;&apos;</span> + options
    } <span class="hljs-keyword">else</span> {
        url += <span class="hljs-string">&apos;?&apos;</span> + options
    }
    <span class="hljs-keyword">return</span> url;
}
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; zhengyuliang all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x7F16;&#x5199;&#x65F6;&#x95F4;&#xFF1A;
2020-09-10 17:32:03
</span></footer></body></html>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="this、apply、call、bind.html" class="navigation navigation-prev " aria-label="Previous page: This、Apply、Call、Bind">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="前端异常的捕获与处理.html" class="navigation navigation-next " aria-label="Next page: 前端异常的捕获与处理">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"前端Js常用的60余种工具方法","level":"4.13","depth":1,"next":{"title":"前端异常的捕获与处理","level":"4.14","depth":1,"path":"javaScript/前端异常的捕获与处理.md","ref":"javaScript/前端异常的捕获与处理.md","articles":[]},"previous":{"title":"This、Apply、Call、Bind","level":"4.12","depth":1,"path":"javaScript/this、apply、call、bind.md","ref":"javaScript/this、apply、call、bind.md","articles":[]},"dir":"ltr"},"config":{"plugins":["sectionx","splitter","tbfed-pagefooter","toggle-chapters","theme-comscore","-lunr","-search","search-plus","donate","anchor-navigation-ex","expandable-chapters","chapter-fold","expandable-chapters-small","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy zhengyuliang","modify_label":"该文件编写时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"pluginsConfig":{"anchor-navigation-ex":{"showLevel":false,"showGoTop":true,"isRewritePageTitle":true,"isShowTocTitleIcon":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"}},"livereload":{},"splitter":{},"donate":{"title":"","button":"赏","wechat":"https://gitee.com/htzyl/img_bed/raw/master/pay/weixin-min.jpg","alipay":"https://gitee.com/htzyl/img_bed/raw/master/pay/alipay-min.jpg","wechatText":"微信打赏","alipayText":"支付宝打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"highlight":{},"anchor-navigation-ex":{"showLevel":true,"associatedWithSummary":true,"mode":"float","showGoTop":true,"printLog":false,"multipleH1":true,"float":{"floatIcon":"fa fa-navicon","showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"theme-comscore":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"zhengyuliang","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"记录技术文档内容","language":"zh-hans","gitbook":">=3.0.0","description":"记录Gitbook的配置和一些插件的使用","theme-default":{"showLevel":true}},"file":{"path":"javaScript/前端js常用的60余种工具方法.md","mtime":"2020-09-10T09:32:03.529Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-01-06T09:44:01.178Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

